﻿#region Disclaimer/Info

/////////////////////////////////////////////////////////////////////////////////////////////////
//
//   File:		HostEnvironment.cs
//   Website:		http://dexterblogengine.com/
//   Authors:		http://dexterblogengine.com/About.ashx
//   Rev:		1
//   Created:		19/01/2011
//   Last edit:		19/01/2011
//   License:		GNU Library General Public License (LGPL)
//   File:            HostEnvironment.cs
//   For updated news and information please visit http://dexterblogengine.com/
//   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
//   For any question contact info@dexterblogengine.com
//
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.IO;
using System.Linq;
using System.Web.Hosting;

namespace Dexter.Web.Core {
	public class HostEnvironment : IHostEnvironment {

		#region IHostEnvironment Members

		public bool IsFullTrust {
			get { return AppDomain.CurrentDomain.IsFullyTrusted; }
		}

		public string MapPath ( string virtualPath ) {
			return HostingEnvironment.MapPath ( virtualPath );
		}

		public bool IsAssemblyLoaded ( string name ) {
			return AppDomain.CurrentDomain.GetAssemblies ( ).Any ( a => a.GetName ( ).Name == name );
		}

		public void RestartAppDomain ( ) {
			ResetSiteCompilation ( );
		}

		public void ResetSiteCompilation ( ) {
			// Touch web.config
			File.SetLastWriteTimeUtc ( MapPath ( "~/web.config" ) , DateTime.UtcNow );
		}

		#endregion
	}
}